// 防抖指令
const debounce = {
    inserted: function (el, binding) {
        let timer
        el.addEventListener('keyup', () => {
            if (timer) {
                clearTimeout(timer)
            }
            timer = setTimeout(() => {
                binding.value()
            }, 1000)
        })
    },
}

export default debounce

//   如何使用？

/**
 <template>
  <button v-debounce="debounceClick">防抖</button>
</template>
 
<script> export default {
  methods: {
    debounceClick () {
      console.log('只触发一次')
    }
  }
}
 </script>
 */